const BaseService = require("./base");

class Service extends BaseService {
	constructor(...args) {
		super(...args);
		this.table = "role";
	}

	async getPerm(id) {
		const res = await this.app.mysql.query(
			`SELECT id FROM perm INNER JOIN role_perm ON perm.id = role_perm.perm_id WHERE role_id = ?`,
			[id]
		);

		return res;
	}

	async setPerm({ role_id, perms }) {
		await this.app.mysql.delete("role_perm", {
			role_id
		});
		perms.forEach(async (perm_id) => {
			await this.app.mysql.insert("role_perm", {
				role_id,
				perm_id
			});
		});
	}
}

module.exports = Service;
